package com.yohann.boot.service.impl;

import com.alibaba.fastjson.JSON;
import com.yohann.boot.common.annotation.InheritedComponent;
import com.yohann.boot.entity.LogRecord;
import com.yohann.boot.service.LogRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author Yeung Wah
 * @since 2022/1/5
 */
@Slf4j
public class PrintLogServiceImpl extends LogRecordService {

    @Async
    @Override
    public void record(LogRecord logRecord) {
        String logMessage = JSON.toJSONString(logRecord);
        if (Objects.isNull(logRecord.getThrowable())) {
            log.info(logMessage);
        } else {
            log.error(logMessage);
        }
    }

    public static void main(String[] args) {
        System.out.println(PrintLogServiceImpl.class.getAnnotation(InheritedComponent.class));
    }

}